package com.silverhaze.diamond.common.entity;

import com.silverhaze.commons.db.datasource.ObjectEntity;

import javax.persistence.Basic;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToOne;

/**
 * SystemUser: Babanin
 * Date: 11.07.2008
 * Time: 0:54:51
 */
@MappedSuperclass
public class CountedDetail extends ObjectEntity {
    private static final long serialVersionUID = 2689127L;

    @Basic
    private int quantity;

    @OneToOne(targetEntity = Detail.class)
    private Detail detail;

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public Detail getDetail() {
        return detail;
    }

    public void setDetail(Detail detail) {
        this.detail = detail;
    }

    public String toString() {
        return detail + " [ count = " + quantity + " ]";
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof CountedDetail)) return false;

        CountedDetail that = (CountedDetail) o;

        if (quantity != that.quantity) return false;
        if (detail != null ? !detail.equals(that.detail) : that.detail != null) return false;

        return true;
    }

    public int hashCode() {
        int result;
        result = quantity;
        result = 31 * result + (detail != null ? detail.hashCode() : 0);
        return result;
    }
}